package com.siwei.mes.entity;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;


/**
 * 工单详情(OrderDetail)实体类
 *
 * @author makejava
 * @since 2023-12-05 09:31:34
 */
@Data
@Table(name = "t_order_detail")
@Accessors(chain = true)
@ApiModel(value = "OrderDetail", description = "工单详情")
public class OrderDetail implements Serializable {
    private static final long serialVersionUID = -59445488930312866L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "工单详情主键ID", name = "id")
    private Long id;
    /**
     * 工单id
     */
    @Column(name = "order_id")
    @ApiModelProperty(value = "工单id", name = "orderId")
    private Long orderId;
    /**
     * 工单类型  字典表 ORDER_TYPE
     */
    @Column(name = "order_type_code")
    @ApiModelProperty(value = "工单类型  字典表 ORDER_TYPE", name = "orderTypeCode")
    private String orderTypeCode;
    /**
     * 工单类型名称
     */
    @Column(name = "order_type_name")
    @ApiModelProperty(value = "工单类型名称", name = "orderTypeName")
    private String orderTypeName;
    /**
     * 工单详情json
     */
    @Column(name = "detail_json")
    @ApiModelProperty(value = "工单详情json", name = "detailJson")
    private JSONObject detailJson;
    /**
     * 工单图片或视频
     */
    @Column(name = "detail_file")
    @ApiModelProperty(value = "工单图片或视频", name = "detailFile")
    private JSONObject detailFile;
    /**
     * 创建人  派单人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人  派单人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    public OrderDetail init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date())
                    .setIsDel(0);
        }
        return this;
    }
}
